package com.base.myproject.client.HR.bcode;


import java.util.Date;

import com.base.myproject.client.tools.Tools;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.base.myproject.client.ui.BaseOpenJSP;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Label;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.VerticalPanel;

public class Rpt_WeekManpower extends BaseJDBCPanel{
	
	private BaseOpenJSP jspPanel = null;
	private String jspFile = "hr_Jsp/rptWeekManpower.jsp";
	private DateField dfBegin = null;
	private DateField dfEnd = null;
	private Button btnQuery = null;
	private Button toExcel = new Button("导出到EXCEL");
	private String data = jspFile + "?b=1";
	
	public Rpt_WeekManpower(){
		init();
	}
	
	public void complete() {
		super.complete();
		print.addListener(Events.OnClick, getListener());
		toExcel.addListener(Events.OnClick, getListener());
		getToolbarll().add(print);
		getToolbarll().add(toExcel);
	}
	
	public void init(){
		initWidget();
	}
	
	public void initWidget(){
		jspPanel = new BaseOpenJSP(jspFile);
		Tools.setResize(jspPanel, 0.99, 0.9);
		jspPanel.getFrame().getElement().setAttribute("frameborder", "0");
		
//		FieldSet fs = new FieldSet();
//		fs.setHeading("查询操作");
		HorizontalPanel hp = new HorizontalPanel();
		hp.setSpacing(3);
		dfBegin = new DateField();
		dfBegin.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		dfEnd = new DateField();
		dfEnd.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		btnQuery = new Button("查询");
		btnQuery.addListener(Events.OnClick, getListener());
		
		hp.add(new Label("开始时间:"));
		hp.add(dfBegin);
		hp.add(new Label("结束时间:"));
		hp.add(dfEnd);
		hp.add(btnQuery);
	//	fs.add(hp);
		
		VerticalPanel vp = new VerticalPanel();
		vp.setSpacing(3);
		vp.add(hp);
		vp.add(jspPanel);
		add(vp);
	}
	
	int sync = 0;                                                      
	Listener<BaseEvent> defaultlistener;                               
                                                                     
	public Listener<BaseEvent> getListener() {                                
		if(defaultlistener!=null)                                        
		{                                                                
			return defaultlistener;                                        
		}                                                                
                                                                     
		defaultlistener = new Listener<BaseEvent>() {                    
			public void handleEvent(BaseEvent be) {                        
				sync++;                                                    
				try {                                                      
					if (sync == 1) {                                   
						if (be.getType() == Events.Select) { 
							
						}else if(be.getType() == Events.OnBlur){
							
						}else if(be.getType() == Events.OnClick){
							if(be.getSource().equals(btnQuery)){
								String beginTime = dfBegin.getRawValue();
								String endTime = dfEnd.getRawValue();
								if(beginTime.equals("") || endTime.equals("")){
									MessageBox.alert("提示", "查询信息填写不完整", null);
								}else {
									data = jspFile + "?beginTime=" + beginTime + "&endTime=" + endTime + "&time=" + new Date().getTime();
									jspPanel.getFrame().setUrl(data);
								}
							} else if (be.getSource().equals(print)) {
								Window.open(GWT.getHostPageBaseURL() + data ,"_blank","menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes");
							} else {
								Window.open(GWT.getHostPageBaseURL() + data + "&excel=1","_blank","menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes");
							}
						}                                          
					}                                                  
				} finally {                                                
					sync--;                                            
				}                                                          
			}                                                              
		};                                                               
		return defaultlistener;                                          
	}
}
